<?php

namespace App\Http\Controllers\AppYx;

use App\Http\Controllers\BaseController;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Tymon\JWTAuth\Facades\JWTAuth;

class UserController extends BaseController
{
	use AuthenticatesUsers {login as doLogin;}

	/**
	 * 登录 返回token
	 * @param Request $request
	 * @return JsonResponse
	 */
	public function login(Request $request)
	{
//		$data=$this->doLogin($request);

		$input = $request->all();

		if (!$token = JWTAuth::attempt($input)) {
			return new JsonResponse(['msg'=>trans('fzs.login.err_user_pass'),'status'=>0], 200);
		}
		dd($token);

	}

	/**
	 * 验证token 获取user信息
	 * @param Request $request
	 * @return JsonResponse
	 */
	public function info(Request $request)
	{
		if (! $user = JWTAuth::parseToken()->authenticate()) {
			return response()->json(['user_not_found'], 404);
		}
		return response()->json(compact('user'));

	}

}
